import request from '@/utils/request'
import type { PageResult, SysUser, PageParams, UserItem, BaseResponse, UserTreeResponse } from '@/types'

// 分页查询用户
export interface UserPageResponse extends BaseResponse {
  result: PageResult<SysUser>
}
export const getUserPageListAPI = (params: PageParams): Promise<UserPageResponse> => {
  return request.get('/api/SysUser/GetPageList', { params })
}

// 添加用户
export const addUserAPI = (data: UserItem): Promise<BaseResponse> => {
  return request.post('/api/SysUser/Insert', data)
}

// 修改用户
export const updateUserAPI = (data: UserItem): Promise<BaseResponse> => {
  return request.post('/api/SysUser/Update', data)
}

// 删除用户
export const deleteUserAPI = (id: string): Promise<BaseResponse> => {
  return request.post('/api/SysUser/DelteByIds', [id])
}

// 根据ID查询用户
export const getUserByIdAPI = (id: string): Promise<BaseResponse> => {
  return request.get('/api/SysUser/GetById', { params: { id } })
}

// 查询用户绑定的权限
export const getLoginInfoAPI = (): Promise<BaseResponse> => {
  return request.get('/api/SysUser/GetLoginInfo')
}

// 查询用户绑定的菜单
export const getUserTreeListAPI = (userid: string): Promise<UserTreeResponse> => {
  return request.get('/api/SysMenu/GetUserTreeList', { params: { userid } })
}
